program Stateless.Tests;

{$IFNDEF TESTINSIGHT}
{$APPTYPE CONSOLE}
{$ENDIF}{$STRONGLINKTYPES ON}

uses
  SysUtils,
{$IFDEF TESTINSIGHT}
  TestInsight.DUnitX,
{$ENDIF }
  DUnitX.Loggers.Console,
  DUnitX.Loggers.Xml.NUnit,
  DUnitX.TestFramework,
  Stateless in '..\Stateless\Stateless.pas',
  Stateless.Types in '..\Stateless\Stateless.Types.pas',
  Stateless.Utils in '..\Stateless\Stateless.Utils.pas',
  Stateless.Tests.TestMachine in 'Stateless.Tests.TestMachine.pas',
  Stateless.Tests.StateRepresentationFixture in 'Stateless.Tests.StateRepresentationFixture.pas',
  Stateless.Tests.TransitionFixture in 'Stateless.Tests.TransitionFixture.pas',
  Stateless.Tests.TransitioningTriggerBehaviourFixture in 'Stateless.Tests.TransitioningTriggerBehaviourFixture.pas',
  Stateless.Tests.DynamicTriggerBehaviourFixture in 'Stateless.Tests.DynamicTriggerBehaviourFixture.pas',
  Stateless.Tests.IgnoredTriggerBehaviourFixture in 'Stateless.Tests.IgnoredTriggerBehaviourFixture.pas',
  Stateless.Tests.TriggerWithParametersFixture in 'Stateless.Tests.TriggerWithParametersFixture.pas',
  Stateless.Tests.StateMachineFixture in 'Stateless.Tests.StateMachineFixture.pas';

var
  runner     : ITestRunner;
  results    : IRunResults;
  logger     : ITestLogger;
  nunitLogger: ITestLogger;

begin
{$IFDEF TESTINSIGHT}
  TestInsight.DUnitX.RunRegisteredTests;
  exit;
{$ENDIF}
  try
    // Check command line options, will exit if invalid
    TDUnitX.CheckCommandLine;
    // Create the test runner
    runner := TDUnitX.CreateRunner;
    // Tell the runner to use RTTI to find Fixtures
    runner.UseRTTI := True;
    // tell the runner how we will log things
    // Log to the console window
    logger := TDUnitXConsoleLogger.Create( True );
    runner.AddLogger( logger );
    // Generate an NUnit compatible XML File
    nunitLogger := TDUnitXXMLNUnitFileLogger.Create( TDUnitX.Options.XMLOutputFile );
    runner.AddLogger( nunitLogger );
    runner.FailsOnNoAsserts := False; // When true, Assertions must be made during tests;

    // Run tests
    results := runner.Execute;
    if not results.AllPassed
    then
      System.ExitCode := EXIT_ERRORS;

{$IFNDEF CI}
    // We don't want this happening when running under CI.
    if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause
    then
      begin
        System.Write( 'Done.. press <Enter> key to quit.' );
        System.Readln;
      end;
{$ENDIF}
  except
    on E: Exception do
      System.Writeln( E.ClassName, ': ', E.Message );
  end;

end.
